<template>
  <div class="app">
    <div class="home">
      <div>
        <div class="header-title">
          <img src="http://124.223.73.204:8080/img/profile/bg.png" alt="" />

          <CheckUser>
            <template #content>
              <div class="Profile-user" v-if="user.nickname">
                <div class="Profile-img">
                  <img
                    :src="'http://124.223.73.204:8080' + user.avatar"
                    alt=""
                  />
                </div>
                <div class="Profile-text">
                  <div class="Profile-name">{{ user.nickname }}</div>
                  <div class="Profile-back">
                    <span @click="back">退出</span>
                  </div>
                  <div class="Profile-edit-user">
                    编辑个人资料 <span><van-icon name="play" /></span>
                  </div>
                </div>
              </div>
            </template>
          </CheckUser>
        </div>

        <div class="am-grid">
          <van-grid :border="false" :column-num="3" :gutter="10">
            <van-grid-item icon="star-o" text="我的收藏"  to="/favoritehouse"></van-grid-item>
            <van-grid-item icon="wap-home-o" text="我的出租"></van-grid-item>
            <van-grid-item icon="clock-o" text="看房记录"></van-grid-item>
            <van-grid-item icon="coupon-o" text="成为房主"></van-grid-item>
            <van-grid-item icon="manager-o" text="个人资料"></van-grid-item>
            <van-grid-item icon="service" text="联系我们"></van-grid-item>
          </van-grid>
        </div>
        <div class="Profile">
          <img src="http://124.223.73.204:8080/img/profile/join.png" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getToken, removeToken } from '@/utils-gongju/storage.js'
import { getUsername } from '@/api-ajax/house.js'
// import instance from '@/utils-gongju/request.js'
import CheckUser from '@/components/CheckUser.vue'
import { Dialog } from 'vant'

export default {
  components: {
    CheckUser,
    [Dialog.Component.name]: Dialog.Component
  },
  data () {
    return {
      user: {},
      toke: ''
    }
  },
  methods: {
    back () {
      Dialog.confirm({
        title: '提示',
        message: '是否确认退出'
      })
        .then(() => {
          // on confirm
          removeToken()
          this.user = ''
        })
        .catch(() => {
          // on cancel
        })
    }
  },
  async created () {
    const data = await getToken()
    // console.log(data)
    this.toke = data
    // const res2 = await instance.get('/user', { headers: { authorization: data } })
    const res2 = await getUsername(data)
    console.log(res2)
    this.user = res2.data.body
  }
}
</script>

<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.home {
  line-height: 1.2;
  padding-bottom: 50px;
  .header-title {
    min-height: 300px;
    position: relative;
    width: 100%;
    // background-color: #fd6262;
    .Profile-user {
      z-index: 1;
      position: absolute;
      background: #fff;
      width: 85%;
      height: 55%;
      bottom: 0px;
      left: 50%;
      transform: translateX(-50%);
      box-shadow: 0px 0px 10px 3px #ddd;
      margin: 50px auto 0;
      padding: 0 20px;
      padding-top: 0;
      text-align: center;
      font-size: 13px;
      .Profile-text {
        padding-top: 15px;
        .Profile-name {
          margin-top: -30px;
          margin-bottom: 10px;
        }
        .Profile-back {
          margin-bottom: 30px;
          span {
            border-radius: 30px;
            color: #fff;
            padding: 2px 15px;
            background: #21b97a;
            font-size: 12px;
          }
        }
        .Profile-edit-user {
          color: #999;
          font-size: 12px;
          margin-top: 20px;
          span {
            // transform: rotate(-90deg);
            display: inline-block;
            margin-left: 3px;
          }
        }
      }
      .Profile-img {
        position: relative;
        transform: translateY(-50%);
        border-radius: 50%;
        width: 70px;
        height: 70px;
        border: solid 5px #f5f5f5;
        display: inline-block;
        box-shadow: 0px 2px 2px #bdbdbd;
      }
    }
    img {
      width: 100%;
    }
  }

  .Profile {
    width: 100%;
    text-align: center;
    margin-top: 10px;
    img {
      width: 92%;
    }
  }
}
</style>
